package com.wtwd.wtwddevice.deviceserver.netty.code;

import com.wtwd.device.protocol.WTProtocol;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class WTEncoder extends MessageToByteEncoder<WTProtocol> {
    @Override
    protected void encode(ChannelHandlerContext ctx, WTProtocol wtProtocol, ByteBuf out) throws Exception {
        out.writeBytes(wtProtocol.serialize().getBytes("utf-8"));
        log.info("channelId:{}服务器发送数据：{}",ctx.channel().id(), wtProtocol.serialize());
    }
}
